using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using MacomberMap.Common.Events;
using MacomberMap.Common.Database_Interface.CIM.One_Line_Interface;
using MacomberMap.Common.Components;
using MacomberMap.Common.Database_Interface.CIM.Components;

namespace MacomberMap.Common.Database_Interface.CIM.Events
{
    /// <summary>
    /// This class handles multiple element errors
    /// </summary>
    public class MM_Event_MultipleElements: MM_Event
    {
        #region Variable declarations
        /// <summary>The Xml component in question</summary>
        public MM_OneLine_XmlComponent Element;

        /// <summary>The elements that could be assigned to this Xml component</summary>
        public CIM_Element[] AssignedElements;
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize a new multiple event handler
        /// </summary>
        /// <param name="Element"></param>
        /// <param name="AssignedElements"></param>
        public MM_Event_MultipleElements(MM_OneLine_XmlComponent Element, params CIM_Element[] AssignedElements)
        {
            this.Element = Element;
            this.AssignedElements = AssignedElements;
        }
        #endregion

        /// <summary>
        /// Build the list view definition for the event
        /// </summary>
        /// <returns></returns>
        public override ListViewItem BuildListViewItem()
        {
            ListViewItem NewItem = new ListViewItem(Element.Name);
            NewItem.SubItems.Add(this.EventState.ToString());
            NewItem.SubItems.Add(TimeText);
            NewItem.ImageIndex = EventType.Index;
            return NewItem;
        }

        /// <summary>
        /// Build the list view definition for the event
        /// </summary>
        /// <param name="lvItem"></param>
        public override void UpdateListViewItem(ListViewItem lvItem)
        {
            lvItem.SubItems[0].Text = Element.Name;
            lvItem.SubItems[1].Text = EventState.ToString();
            lvItem.SubItems[2].Text = TimeText;
        }

        /// <summary>
        /// Display details of the event
        /// </summary>
        /// <param name="OutParent"></param>
        public override void DisplayDetails(Control OutParent)
        {
            TreeView tvOut = new TreeView();
            tvOut.Dock = DockStyle.Fill;
            this.AddNodeItem("Element", Element, tvOut.Nodes);
            this.AddNodeItem("Assigned Elements", AssignedElements, tvOut.Nodes);            
            tvOut.Nodes[0].EnsureVisible();
            OutParent.Controls.Add(tvOut);
        }

        /// <summary>
        /// Add menu items for the event
        /// </summary>
        /// <param name="OutMenu"></param>
        public override void AddMenuItems(ContextMenuStrip OutMenu)
        {
            //throw new Exception("The method or operation is not implemented.");
        }

        /// <summary>
        /// Compare the event to others
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override int CompareTo(object obj)
        {
            return String.Compare(Element.Name, (obj as MM_Event_MoreParents).Element.Name, true);                            
        }
    }
}
